<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>域名替换</title>
    <link href="/layui/css/layui.css" rel="stylesheet">
    <script src="/layui/js/layui.js"></script>
    <script src="/layui/js/axios.min.js"></script>
    <link rel="shortcut icon" href="/favicon.ico"/>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree layui-nav-side">
                <li class="layui-nav-item layui-this"><a href="javascript:;">域名替换</a></li>
            </ul>
        </div>
    </div>
    <div class="layui-body" style="top:15px;">
        <div style="padding-left: 16px;padding-right: 16px;">
            <form class="layui-form layui-form-pane" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label">组号</label>
                    <div class="layui-input-block">
                        <input type="text" name="group_no" value="{$gno}" lay-affix="clear" disabled class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">新域名</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请直接从Excel复制原始和新的域名这两个列过来即可" class="layui-textarea" lay-verify="required" name="domains" rows="25"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit lay-filter="commit">确认</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function(){
        var form = layui.form;
        var layer = layui.layer;

        // 提交
        form.on('submit(commit)', function(data){
            var field = data.field; // 获得表单字段
            // 执行 Ajax 等操作
            axios.post('/tool/domain', {
                group_no:field.group_no,domains:field.domains
            }).then((success) => {
                console.log(success);
                if (success.data.code == 200) {
                    layer.msg(success.data.message, {icon: 1});
                } else {
                    layer.msg(success.data.message, {icon: 2});
                }
            }).catch(error=>{
                // 处理错误
                if (error.response) {
                    // 请求已发出，服务器响应了状态码，但状态码超出了 2xx 的范围
                    console.error('Error Status:', error.response.status);
                    console.error('Error Data:', error.response.data.message);
                    layer.msg(error.response.data.message, {icon: 2});
                } else if (error.request) {
                    // 请求已发出，但没有收到响应
                    console.error('No response received:', error.request);
                } else {
                    // 其他错误
                    console.error('Error Message:', error.message);
                }
            });
            return false; // 阻止默认 form 跳转
        });
    });
</script>
</body>
</html>